import { _decorator, Component, Game, Label, Node } from 'cc';
import { kuModel } from '../KugoModel';
import { GameState, SeatType } from '../proto/proto';
import { EventMgr } from '../../../../scripts/GlobalMessage';
import { KugoEvent } from '../KugoConst';
const { ccclass, property } = _decorator;

@ccclass('CenterNode')
export class CenterNode extends Component {
    @property(Node)
    GameStateNode:Node = null
    @property(Node)
    OptUserNode:Node = null
    
    protected onLoad(): void {
        EventMgr.on(KugoEvent.RefreshGameState, this.RefreshState, this)
    }

    RefreshState(){
        let model = kuModel

        let stateLab = this.GameStateNode.getChildByName("GameState").getComponent(Label)
        if(model.ChessBase.GameState == GameState.Wait){
            stateLab.string = "等待开始"
        }else if(model.ChessBase.GameState == GameState.DropPieces){
            stateLab.string = "落子阶段"
        }else if(model.ChessBase.GameState == GameState.Jump){
            stateLab.string = "跳子阶段"
        }else if(model.ChessBase.GameState == GameState.Fly){
            stateLab.string = "飞子阶段"
        }else{
            stateLab.string = "结算阶段"
        }

        let tipsLab = this.OptUserNode.getChildByName("Tips").getComponent(Label)
        if (model.ChessBase.CurSeat == SeatType.BLACK) {
            tipsLab.string = "该黑方出手了"
        }else if (model.ChessBase.CurSeat == SeatType.WHITE){
            tipsLab.string = "该白方出手了"
        }

    }
}


